package com.blustreaksw.cyclecoach;

import com.blustreaksw.cyclecoach.R;
import com.blustreaksw.cyclecoach.R.id;
import com.blustreaksw.cyclecoach.R.layout;
import com.blustreaksw.cyclecoach.R.menu;
import com.blustreaksw.cyclecoach.data.UserProfile;
import com.blustreaksw.cyclecoach.userManagment.Fragment_List_SelectUser;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class UserManagementActivity extends UserProfileActivity {
	
	public static final String FRAGMENT_USER_PROFILE = "fragment_userProfile";
	public static final String FRAGMENT_SENSOR_CONFIGURATION = "fragment_sensorConfiguration";
	public static final String FRAGMENT_DATA_EXPORT = "fragment_dataExport";
	public static final String FRAGMENT_DEVICE_SEARCH = "fragment_deviceSearch";
	public static final String FRAGMENT_SELECT_USER = "fragment_selectUser";
	
	private UserProfile mUserProfile;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setUsedForWizard(true);
		
		if(findViewById(R.id.fragmentContainer) != null) {
			
			if(savedInstanceState != null) {
				return;
			}
			
			Fragment fragment;
			if((fragment = getSupportFragmentManager().
					findFragmentByTag(UserManagementActivity.FRAGMENT_SELECT_USER)) == null) {
				fragment = new Fragment_List_SelectUser();
			}
			
			getSupportFragmentManager().beginTransaction()
				.add(R.id.fragmentContainer, fragment, UserManagementActivity.FRAGMENT_SELECT_USER)
				.commit();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_user_management, menu);
		return true;
	}
	
	@Override
	public void onResume() {
		super.onResume();
		
		if(mUserProfile == null) {
			mUserProfile = UserProfile.getInstance(getApplicationContext());
		}
	}

}
